﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using OfficeOpenXml;
using System.IO;

namespace Topro.Admin.Controllers
{

    using System.Net.Http;
    using Topro.Application.Interface;
    using Topro.Entity;
    using Topro.Entity.Enum;
    using Topro.Entity.Query;
    using Topro.Entity.Request.Config;
    using Topro.Entity.Response.Config;
    using Topro.Util;

    /// <summary>
    /// 配置
    /// </summary>
    public class ConfigController : BaseController
    {
        #region 注入
        /// <summary>
        /// 设置接口
        /// </summary>
        private readonly SettingService _settingService;

        /// <summary>
        /// 配置接口
        /// </summary>
        private readonly ConfigService _configService;

        /// <summary>
        /// 
        /// </summary>
        private readonly IWebHostEnvironment _webHostEnvironment;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="authService">设置接口</param>
        /// <param name="configService">配置接口</param>
        public ConfigController(SettingService settingService, ConfigService configService, IWebHostEnvironment webHostEnvironment)
        {
            _settingService = settingService;
            _configService = configService;
            _webHostEnvironment = webHostEnvironment;
        }
        #endregion

        #region 列表
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }
        #endregion

        #region 设定

        #region 程序
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.ProgramSetUp0001)]
        public IActionResult ProgramSetUp()
        {
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        [AuthFilter(AuthCode.ProgramSetUp0001)]
        public IActionResult ProgramSetUpQuery(ConfigQuery query)
        {
            query.Type = (int)SettingType.程序;
            var list = _configService.GetPager(query);

            return PartialView("_ProgramSetUpQuery", list);
        }

        /// <summary>
        /// 员工号限制
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.ProgramSetUp0002, AuthCode.ProgramSetUp0003)]
        public IActionResult ProgramSetUpAddOrEdit(int? id)
        {
            var model = new ConfigResponse();
            if (id.HasValue)
            {
                model = _configService.Get(id.Value);
            }
            return View("ProgramSetUpAddOrEdit", model);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.ProgramSetUp0002, AuthCode.ProgramSetUp0003)]
        public IActionResult ProgramSetUpSave(ConfigRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(request.PartNo))
                {
                    throw new Exception("料号不能为空.");
                }

                if(string.IsNullOrEmpty(request.Cycle))
                {
                    throw new Exception("叠合次数号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Remark))
                {
                    throw new Exception("备注不能为空.");
                }

                request.Ip = Ip;
                request.UserId = UserId;
                request.Type = (int)SettingType.程序;
                response = _configService.SaveConfig(request);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Book结构
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.BookSetUp0001)]
        public IActionResult BookSetUp()
        {
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        [AuthFilter(AuthCode.BookSetUp0001)]
        public IActionResult BookSetUpQuery(ConfigQuery query)
        {
            query.Type = (int)SettingType.Book结构;

            var list = _configService.GetPager(query);

            return PartialView("_BookSetUpQuery", list);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.BookSetUp0002, AuthCode.BookSetUp0003)]
        public IActionResult BookSetUpAddOrEdit(int? id)
        {
            var model = new ConfigResponse();
            if (id.HasValue)
            {
                model = _configService.Get(id.Value);
            }
            return View("BookSetUpAddOrEdit", model);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.BookSetUp0002, AuthCode.BookSetUp0003)]
        public IActionResult BookSetUpSave(ConfigRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(request.PartNo))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Cycle))
                {
                    throw new Exception("叠合次数号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Value))
                {
                    throw new Exception("满本结构不能为空.");
                }

                if (string.IsNullOrEmpty(request.Remark))
                {
                    throw new Exception("备注不能为空.");
                }

                request.Ip = Ip;
                request.UserId = UserId;
                request.Type = (int)SettingType.Book结构;
                response = _configService.SaveConfig(request);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }

        #endregion

        #region 叠板片数设定
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.HeapSetUp0001)]
        public IActionResult HeapSetUp()
        {
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        [AuthFilter(AuthCode.HeapSetUp0001)]
        public IActionResult HeapSetUpQuery(ConfigQuery query)
        {
            query.Type = (int)SettingType.叠板片数设定;

            var list = _configService.GetPager(query);

            return PartialView("_HeapSetUpQuery", list);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.HeapSetUp0002, AuthCode.HeapSetUp0003)]
        public IActionResult HeapSetUpAddOrEdit(int? id)
        {
            var model = new ConfigResponse();
            if (id.HasValue)
            {
                model = _configService.Get(id.Value);
            }
            return View("HeapSetUpAddOrEdit", model);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.HeapSetUp0002, AuthCode.HeapSetUp0003)]
        public IActionResult HeapSetUpSave(ConfigRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(request.PartNo))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Cycle))
                {
                    throw new Exception("叠合次数号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Value))
                {
                    throw new Exception("叠板数不能为空.");
                }

                if (string.IsNullOrEmpty(request.Remark))
                {
                    throw new Exception("备注不能为空.");
                }

                request.Ip = Ip;
                request.UserId = UserId;
                request.Type = (int)SettingType.叠板片数设定;
                response = _configService.SaveConfig(request);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }

        #endregion

        #region 操作设定
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.OPSetUp0001)]
        public IActionResult OPSetUp()
        {
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        [AuthFilter(AuthCode.OPSetUp0001)]
        public IActionResult OPSetUpQuery(ConfigQuery query)
        {
            query.Type = (int)SettingType.操作设定;

            var list = _configService.GetPager(query);

            return PartialView("_OPSetUpQuery", list);
        }

        /// <summary>
        /// 导出
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.OPSetUp0001)]
        public IActionResult ExportExcel(ConfigQuery query)
        {
            query.PageIndex = 1;
            query.PageSize = 10000;
            query.Type = (int)SettingType.操作设定;
            //获取数据
            var list = _configService.GetPager(query);
            //文件名称
            var fileName = @$"{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
            //路径
            var filePath = Path.Combine(@$"{_webHostEnvironment.WebRootPath}", fileName);
            //文件对象
            FileInfo file = new FileInfo(filePath);
            //是否存在
            if (file.Exists)
            {
                file.Delete();
            }
            //指定EPPlus使用非商业证书
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            using (ExcelPackage package = new ExcelPackage(file))
            {
                //创建sheet
                ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("IQS");
                //worksheet.Cells.LoadFromCollection(list, true);
                //头部
                worksheet.Cells[1, 1].Value = "料号";
                worksheet.Cells[1, 2].Value = "批号";
                worksheet.Cells[1, 3].Value = "叠合次数号";
                worksheet.Cells[1, 4].Value = "内容";
                worksheet.Cells[1, 5].Value = "备注";
                worksheet.Cells[1, 6].Value = "最后更新时间";
                //行数
                int row = 2;

                foreach (var item in list.TData)
                {
                    worksheet.Cells[row, 1].Value = item.PartNo;
                    worksheet.Cells[row, 2].Value = item.LotNo;
                    worksheet.Cells[row, 3].Value = item.Cycle;
                    if (!string.IsNullOrEmpty(item.Value))
                    {
                        worksheet.Cells[row, 4].Value = WebUtil.StripHTML(item.Value);
                    }
                    worksheet.Cells[row, 5].Value = item.Remark;
                    worksheet.Cells[row, 6].Value = item.UpdateDate.ToString("yyyy-MM-dd HH:mm:ss");
                    row++;
                }
                package.Save();
            }

            return File(new FileStream(filePath, FileMode.Open), "application/octet-stream", fileName);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.OPSetUp0002, AuthCode.OPSetUp0003)]
        public IActionResult OPSetUpAddOrEdit(int? id)
        {
            var model = new ConfigResponse();
            if (id.HasValue)
            {
                model = _configService.Get(id.Value);
            }
            return View("OPSetUpAddOrEdit", model);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.OPSetUp0002, AuthCode.OPSetUp0003)]
        public IActionResult OPSetUpSave(ConfigRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(request.PartNo))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Cycle))
                {
                    throw new Exception("叠合次数号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Value))
                {
                    throw new Exception("内容不能为空.");
                }

                if (string.IsNullOrEmpty(request.Remark))
                {
                    throw new Exception("备注不能为空.");
                }

                request.Ip = Ip;
                request.UserId = UserId;
                request.Type = (int)SettingType.操作设定;
                response = _configService.SaveConfig(request);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }

        #endregion

        #region 机台设定
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.MachineSetUp0001)]
        public IActionResult MachineSetUp()
        {
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        [AuthFilter(AuthCode.MachineSetUp0001)]
        public IActionResult MachineSetUpQuery(ConfigQuery query)
        {
            query.Type = (int)SettingType.机台设定;

            var list = _configService.GetPager(query);

            return PartialView("_MachineSetUpQuery", list);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.MachineSetUp0002, AuthCode.MachineSetUp0003)]
        public IActionResult MachineSetUpAddOrEdit(int? id)
        {
            var model = new ConfigResponse();
            if (id.HasValue)
            {
                model = _configService.Get(id.Value);
            }
            return View("MachineSetUpAddOrEdit", model);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.MachineSetUp0002, AuthCode.MachineSetUp0003)]
        public IActionResult MachineSetUpSave(ConfigRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(request.PartNo))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Cycle))
                {
                    throw new Exception("叠合次数号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Value))
                {
                    throw new Exception("机台不能为空.");
                }

                if (string.IsNullOrEmpty(request.Remark))
                {
                    throw new Exception("备注不能为空.");
                }

                request.Ip = Ip;
                request.UserId = UserId;
                request.Type = (int)SettingType.机台设定;
                response = _configService.SaveConfig(request);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #endregion

        #region 限制

        #region 材料限制
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.MaterialLimit0001)]
        public IActionResult MaterialLimit()
        {
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        [AuthFilter(AuthCode.MaterialLimit0001)]
        public IActionResult MaterialLimitQuery(ConfigQuery query)
        {
            query.Type = (int)SettingType.材料限制;

            var list = _configService.GetPager(query);

            return PartialView("_MaterialLimitQuery", list);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.MaterialLimit0002, AuthCode.MaterialLimit0003)]
        public IActionResult MaterialLimitAddOrEdit(int? id)
        {
            var model = new ConfigResponse();
            if (id.HasValue)
            {
                model = _configService.Get(id.Value);
            }

            ViewBag.materialFieldType = EnumUtil.ToDictionary(typeof(MaterialFieldType));

            return View("MaterialLimitAddOrEdit", model);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.MaterialLimit0002, AuthCode.MaterialLimit0003)]
        public IActionResult MaterialLimitSave(ConfigRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(request.PartNo))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Cycle))
                {
                    throw new Exception("叠合次数号不能为空.");
                }

                if (request.FieldType<=0)
                {
                    throw new Exception("请选择字段类型.");
                }

                if (string.IsNullOrEmpty(request.Value))
                {
                    throw new Exception("值不能为空.");
                }

                if (string.IsNullOrEmpty(request.Remark))
                {
                    throw new Exception("备注不能为空.");
                }

                request.Ip = Ip;
                request.UserId = UserId;
                request.Type = (int)SettingType.材料限制;
                response = _configService.SaveMaterialLimit(request);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region 机台限制
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.MachineLimit0001)]
        public IActionResult MachineLimit()
        {
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        [AuthFilter(AuthCode.MachineLimit0001)]
        public IActionResult MachineLimitQuery(ConfigQuery query)
        {
            query.Type = (int)SettingType.机台限制;

            var list = _configService.GetPager(query);

            return PartialView("_MachineLimitQuery", list);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.MachineLimit0002, AuthCode.MachineLimit0003)]
        public IActionResult MachineLimitAddOrEdit(int? id)
        {
            var model = new ConfigResponse();
            if (id.HasValue)
            {
                model = _configService.Get(id.Value);
            }
            return View("MachineLimitAddOrEdit", model);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.MachineLimit0002, AuthCode.MachineLimit0003)]
        public IActionResult MachineLimitSave(ConfigRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(request.PartNo))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Cycle))
                {
                    throw new Exception("叠合次数号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Value))
                {
                    throw new Exception("机台不能为空.");
                }

                if (string.IsNullOrEmpty(request.Remark))
                {
                    throw new Exception("备注不能为空.");
                }

                request.Ip = Ip;
                request.UserId = UserId;
                request.Type = (int)SettingType.机台限制;
                response = _configService.SaveConfig(request);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }

        #endregion

        #region 员工号限制
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.StaffLimit0001)]
        public IActionResult StaffLimit()
        {
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        [AuthFilter(AuthCode.StaffLimit0001)]
        public IActionResult StaffLimitQuery(ConfigQuery query)
        {
            query.Type = (int)SettingType.员工号限制;

            var list = _configService.GetPager(query);

            return PartialView("_StaffLimitQuery", list);
        }

        /// <summary>
        /// 员工号限制
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.StaffLimit0002, AuthCode.StaffLimit0003)]
        public IActionResult StaffLimitAddOrEdit(int? id)
        {
            var model = new ConfigResponse();
            if (id.HasValue)
            {
                model = _configService.Get(id.Value);
            }
            return View("StaffLimitAddOrEdit", model);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.StaffLimit0002, AuthCode.StaffLimit0003)]
        public IActionResult StaffLimitSave(ConfigRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(request.PartNo))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Cycle))
                {
                    throw new Exception("叠合次数号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Value))
                {
                    throw new Exception("员工工号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Remark))
                {
                    throw new Exception("备注不能为空.");
                }

                request.Ip = Ip;
                request.UserId = UserId;
                request.Type = (int)SettingType.员工号限制;
                response = _configService.SaveConfig(request);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }

        #endregion

        #region 产品限制
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.ProductLimit0001)]
        public IActionResult ProductLimit()
        {
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        [AuthFilter(AuthCode.ProductLimit0001)]
        public IActionResult ProductLimitQuery(ConfigQuery query)
        {
            query.Type = (int)SettingType.产品限制;

            var list = _configService.GetPager(query);

            return PartialView("_ProductLimitQuery", list);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.ProductLimit0002, AuthCode.ProductLimit0003)]
        public IActionResult ProductLimitAddOrEdit(int? id)
        {
            var model = new ConfigResponse();
            if (id.HasValue)
            {
                model = _configService.Get(id.Value);
            }
            return View("ProductLimitAddOrEdit", model);
        }

        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <returns></returns>
        [AuthFilter(AuthCode.ProductLimit0002, AuthCode.ProductLimit0003)]
        public IActionResult ProductLimitSave(ConfigRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(request.PartNo))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Cycle))
                {
                    throw new Exception("叠合次数号不能为空.");
                }

                if (string.IsNullOrEmpty(request.Remark))
                {
                    throw new Exception("备注不能为空.");
                }

                request.Ip = Ip;
                request.UserId = UserId;
                request.Type = (int)SettingType.产品限制;
                response = _configService.SaveConfig(request);
            }
            catch(Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #endregion

        #region 更新状态  
        /// <summary>
        /// 更新状态
        /// </summary>
        /// <param name="id">编号</param>
        /// <param name="status">状态</param>
        /// <returns></returns>
        [HttpPost]
        [AuthFilter(AuthCode.ProgramSetUp0001, AuthCode.BookSetUp0001, AuthCode.HeapSetUp0001, AuthCode.OPSetUp0001, AuthCode.MaterialLimit0001, AuthCode.MachineLimit0001, AuthCode.StaffLimit0001, AuthCode.ProductLimit0001)]
        public JsonResult Updatestatus(int id, sbyte status)
        {
            var response = new JResult()
            {
                Success = false
            };

            response = _configService.Updatestatus(id, status);

            return Json(response);
        }
        #endregion

        #region 缓存
        public void Cache()
        {
            try
            {
                using (var client = new HttpClient())
                {
                    var res = client.GetAsync("http://localhost:5000/Home/cache");
                }
            }
            catch (Exception ex)
            {
            }
        }
        #endregion

        #region 新增、编辑
        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <param name="request">参数</param>
        /// <returns></returns>
        public JsonResult ConfigSave(ConfigRequest request)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                if (request.Type <= 0)
                {
                    throw new Exception("参数错误.");
                }

                if(string.IsNullOrEmpty(request.LotNo))
                {
                    throw new Exception("Lot No 不能为空.");
                }

                if (string.IsNullOrEmpty(request.PartNo))
                {
                    throw new Exception("PartNo 不能为空.");
                }

                if (string.IsNullOrEmpty(request.Cycle))
                {
                    throw new Exception("Cycle 不能为空.");
                }

                if (string.IsNullOrEmpty(request.Cycle))
                {
                    throw new Exception("Cycle 不能为空.");
                }
            }
            catch(Exception ex)
            {
                response.Message = ex.Message;
            }

            response = _configService.SaveConfig(request);

            return Json(response);
        }
        #endregion
    }
}
